package com.kld.yqyj.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kld.common.annotation.RepeatSubmit;
import com.kld.common.annotation.Log;
import com.kld.common.core.controller.BaseController;
import com.kld.common.core.domain.PageQuery;
import com.kld.common.core.domain.R;
import com.kld.common.core.validate.AddGroup;
import com.kld.common.core.validate.EditGroup;
import com.kld.common.core.validate.QueryGroup;
import com.kld.common.enums.BusinessType;
import com.kld.common.utils.poi.ExcelUtil;
import com.kld.yqyj.domain.vo.TOFdbMVo;
import com.kld.yqyj.domain.bo.TOFdbMBo;
import com.kld.yqyj.service.ITOFdbMService;
import com.kld.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 油藏开发单元月数据Controller
 *
 * @author bw
 * @date 2024-05-15
 */
@Validated
@Api(value = "油藏开发单元月数据控制器", tags = {"油藏开发单元月数据管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/yqyj/oFdbM")
public class TOFdbMController extends BaseController {

    private final ITOFdbMService iTOFdbMService;

    /**
     * 查询油藏开发单元月数据列表
     */
    @ApiOperation("查询油藏开发单元月数据列表")
    @SaCheckPermission("yqyj:oFdbM:list")
    @GetMapping("/list")
    public TableDataInfo<TOFdbMVo> list(@Validated(QueryGroup.class) TOFdbMBo bo, PageQuery pageQuery) {
        return iTOFdbMService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出油藏开发单元月数据列表
     */
    @ApiOperation("导出油藏开发单元月数据列表")
    @SaCheckPermission("yqyj:oFdbM:export")
    @Log(title = "油藏开发单元月数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated TOFdbMBo bo, HttpServletResponse response) {
        List<TOFdbMVo> list = iTOFdbMService.queryList(bo);
        ExcelUtil.exportExcel(list, "油藏开发单元月数据", TOFdbMVo.class, response);
    }

    /**
     * 获取油藏开发单元月数据详细信息
     */
    @ApiOperation("获取油藏开发单元月数据详细信息")
    @SaCheckPermission("yqyj:oFdbM:query")
    @GetMapping("/{geoUnitId}")
    public R<TOFdbMVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("geoUnitId") String geoUnitId) {
        return R.ok(iTOFdbMService.queryById(geoUnitId));
    }

    /**
     * 新增油藏开发单元月数据
     */
    @ApiOperation("新增油藏开发单元月数据")
    @SaCheckPermission("yqyj:oFdbM:add")
    @Log(title = "油藏开发单元月数据", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TOFdbMBo bo) {
        return toAjax(iTOFdbMService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改油藏开发单元月数据
     */
    @ApiOperation("修改油藏开发单元月数据")
    @SaCheckPermission("yqyj:oFdbM:edit")
    @Log(title = "油藏开发单元月数据", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TOFdbMBo bo) {
        return toAjax(iTOFdbMService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除油藏开发单元月数据
     */
    @ApiOperation("删除油藏开发单元月数据")
    @SaCheckPermission("yqyj:oFdbM:remove")
    @Log(title = "油藏开发单元月数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{geoUnitIds}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] geoUnitIds) {
        return toAjax(iTOFdbMService.deleteWithValidByIds(Arrays.asList(geoUnitIds), true) ? 1 : 0);
    }
}
